<template>
  <div class="login-panel">
    <h1 class="title single-line-text-overflow" :title="$t('login.title')">
      {{ $t('login.title') }}
    </h1>
    <el-tabs v-model="activeName" type="border-card" :stretch="true">
      <el-tab-pane name="account">
        <template #label>
          <span class="custom-tabs-label">
            <el-icon> <User /></el-icon>
            <span :title="$t('login.accountLogin')">{{
              $t('login.accountLogin')
            }}</span>
          </span>
        </template>
        <loginAccount ref="loginAccountRef"></loginAccount>
      </el-tab-pane>
      <el-tab-pane name="phone">
        <template #label>
          <span class="custom-tabs-label">
            <el-icon> <Iphone /></el-icon>
            <span :title="$t('login.mobileLogin')">{{
              $t('login.mobileLogin')
            }}</span>
          </span>
        </template>
      </el-tab-pane>
    </el-tabs>
    <div class="account-control">
      <el-checkbox
        v-model="isRemPwd"
        :label="$t('login.remRwd')"
        size="large"
        :title="$t('login.remRwd')"
      />
    </div>
    <el-button
      type="primary"
      class="login-btn"
      :title="$t('login.signLogin')"
      @click="handleLoginAccount"
      >{{ $t('login.signLogin') }}</el-button
    >
  </div>
</template>

<script setup lang="ts">
import { ref, watch } from 'vue'
import loginAccount from './login-account.vue'
import { localCache } from '@/cache'
const activeName = ref('account')
const isRemPwd = ref<boolean>(localCache.getItem('isRemPwd') ?? false)
const loginAccountRef = ref<InstanceType<typeof loginAccount>>()
watch(isRemPwd, (newValue) => {
  localCache.setItem('isRemPwd', newValue)
})
const handleLoginAccount = () => {
  if (activeName.value === 'account') {
    console.log('账号登录')
    loginAccountRef.value?.loginAction(isRemPwd.value)
  } else {
    console.log('手机登录')
  }
}
</script>

<style lang="less" scoped>
.login-panel {
  margin-bottom: 150px;
  width: 320px;
  .title {
    text-align: center;
  }
  .custom-tabs-label {
    display: flex;
    align-items: center;
    i {
      margin-right: 5px;
    }
  }
  .account-control {
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
  }

  .login-btn {
    width: 100%;
    margin-top: 10px;
  }
}
</style>
